﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using System.Linq;
using T.FAS.Runtime.Expression.Entity;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.Expression.SPI;
using Newtonsoft.Json;
using T.ServiceComponent.DataAccessEx.Core;
using T.FAS.Runtime.Base.Common;

namespace T.FAS.Runtime.Expression.Service
{
    public class DebugExecutor : DynamicObject, IDynamicActionAdapter
    {
        /// <summary>
        /// JS脚本动态调用Dynamic必备函数
        /// 脚本写法：WF.DQ_GetUser();
        /// </summary>
        /// <param name="name">动态调用DynamicObject中的函数名称</param>
        /// <param name="args">参数信息，参数类型必须增加 params</param>
        /// <returns></returns>
        public object DynamicInvoke(string name, params object[] args)
        {
            throw new FasException(ExprExceptionCode.NotSupported, "Unsupported Debug." + name);
        }

        public void Log(object obj)
        {
            ExprService.debugLog.Add(new DebugLog { Creator = UserUtil.GetCurrentUserName(), CreateTime = DateTime.Now.ToString(), Message = obj});
        }

        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            result = DynamicInvoke(binder.Name, args);
            return true;
        }
    }
}
